package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.models.auth.In;
import io.swagger.v3.oas.models.security.SecurityScheme;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/category")
@Slf4j
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @PostMapping
    public Result add(@RequestBody CategoryDTO categoryDTO){
        /*
        * 分类添加
        * */
        log.info("添加的是：{}"+categoryDTO);
        categoryService.sava(categoryDTO);
        return Result.success();
    }
    @GetMapping("/page")
    public Result<PageResult> Selcet(CategoryPageQueryDTO categoryPageQueryDTO){
        /*
        * 分页查询
        * */
        log.info("分页查询：{}",categoryPageQueryDTO);
       PageResult pageResult =  categoryService.select(categoryPageQueryDTO);
       return Result.success(pageResult);
    }
    /*
    根据id删除
    * */
    @DeleteMapping
    public Result<String> deldte( long  id){
        log.info("id是：{}",id);
        categoryService.Delte(id);
        return Result.success();
    }
    /*
    * 根据id修改数据
    * */
    @PutMapping
    public Result update(@RequestBody CategoryDTO categoryDTO){
    log.info("修改的是：{}",categoryDTO);
    categoryService.update(categoryDTO);
    return Result.success();
    }
/*
* 启用 禁用
* */
    @PostMapping("/status/{status}")
    public Result statue(@PathVariable Integer status, long id){
        categoryService.status(status,id);
        return Result.success();
    }
    /*
     * 根据类型查询数据
     * */
    @GetMapping("/list")
    public Result<List<Category>> list(Integer type){
        log.info("类型是：{}",type);
   List<Category> list =  categoryService.list(type);
   return Result.success(list);
    }
}
